// import Vue from 'vue'
// import VueRouter from 'vue-router'
import admin from './components/admin'
// Vue.use(VueRouter);
import {createRouter, createWebHashHistory} from 'vue-router'
import {  message  } from 'ant-design-vue';
// const routerHistory = createWebHistory();

const router = new createRouter({
  history: createWebHashHistory(process.env.BASE_URL),
  /*
   *   在这里和vue2一样写路由配置
  */


    routes : [
    /**
     * 单独页面
     */
    {
      path: '/',
      name: 'Login',
      redirect: '/login',
      meta: {
        title: '登录'
      },
    },
    {
      path: '/login',
      name: 'Home',
      component: () => import('@/views/Login.vue'),
      meta: {
        title: '登录'
      },

    },
    {
      path: '/edit',
      name: 'edit',
      component: () => import('@/views/page/article/Index.vue'),
      meta: {
        title: '编辑'
      },
    },{
      path: '/list',
      name: 'list',
      component: () => import('@/views/page/article/List.vue'),
        meta: {
          title: '文章列表'
        },
    },{
      path: '/detail',
      name: 'detail',
      component: () => import('@/views/page/article/ShowArticle.vue'),
        meta: {
          title: '文章详情'
        },
    },{
      path: '/picture',
      name: 'picture',
      component: () => import('@/views/page/picture/Index.vue'),
        meta: {
          title: '照片墙'
        },
    },
    ...admin

  ],


});

// BAD 守卫路由
router.beforeEach((to, from, next) => {
  // console.log(document.cookie)
  // console.log(to, "from"+from, next)

  if(to.name !== 'Home' &&to.name !== 'Login' && to.name !== 'list' && to.name !== 'detail' && to.name !== 'picture'){
    if(document.cookie && (document.cookie.indexOf('limitName')!==-1 && document.cookie.indexOf('ps')!==-1 && document.cookie.indexOf('cursorUsername')!==-1)){
        next()
    }else{
      message.error("请重新登录");
      setTimeout(function () {
        window.open("https://wuyunxia.top/admin/", "_self");
      }, 300)
    }
  }
  // if (to.name !== 'Login' && !isAuthenticated) next({ name: 'Login' })
  // 如果用户未能验证身份，则 `next` 会被调用两次
  next()
})


// const router = new VueRouter({
//   mode: 'hash',
//   base: process.env.BASE_URL,
//   routes
// });

export default router;
